package com.example.helllo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class CountRateActivity extends AppCompatActivity {
    private static final String TAG = "CountRateActivity";
    TextView country,rateresult;
    EditText rmb;
    float rate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_count_rate);
        //接收数据
        Intent intent= getIntent();
        String countryStr=intent.getStringExtra("count_country");
        String rateStr=intent.getStringExtra("count_rate");
        Log.i(TAG,"countryStr=" + countryStr);
        Log.i(TAG,"rateStr=" + rateStr);
        rate=100f/Float.valueOf(rateStr);
        country=findViewById(R.id.country);
        country.setText(countryStr);
        rateresult=findViewById(R.id.rateResult);
        rmb=findViewById(R.id.RMB);
        rmb.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //获取用户输入数据
                String str =s.toString();
                if(str!=null && str.length()>0){
                    float r=Float.parseFloat(str)*rate;
                    rateresult.setText("结果为"+r);
                }

            }
        });

    }
//    public void click(View btn){
//        String money=rmb.getText().toString();
//        if(money!=null&& money.length()>0){
//            float value = Float.valueOf(money);
//            float result = value*rate;
//            rateresult.setText("转换后的金额为"+result);
//        }else{
//            Toast.makeText(this, "请输入金额", Toast.LENGTH_SHORT).show();
//        }
//    }
}